package servlet;

import utils.ValidateCodeWithImage;

import javax.imageio.ImageIO;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "Servlet1", value = "/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ImageIO
                .write(new ValidateCodeWithImage().getBufferedImage(),
                        "png",
                        response.getOutputStream());
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("content-type","text/html;charset=utf-8");
        response.setHeader("refresh","3,URL=/login.html");
        response.getWriter().write("登录失败，3秒后即将返回到登录界面");

    }
}
